广泛应用在票据打印机上。SDK 中大约有200条生成指令的函数。
| 类名 | 所在位置 | 功能 |
|---|---|---|
| PTCommandESC | PrinterCommand.framewok | ESC 基础指令 |
| PTDispatcher | PrinterDispatch.framework | 与打印机通讯 |
| PTFunctionESC | Demo | 对基础指令封装形成功能 |
| PTTestESC | Demo | 测试基础指令或封装后的功能 |
一个典型的 ESC-POS 指令生成流程如下:
1/**2* 打印条形码3*4* @param justification page 165. 对齐方式 取值0,1,2 : 左、中、右5* @param type page 339. 取值:(A:0~6),(B:65~73)6* @param width page 355. 取值:(2~6),(68~76)7* @param height page 337. 取值:(1~255)8* @param hri_position page 332. 取值:(0~3),(48~51)9* @param barcode page 339.10*11* @return 生成的条形码十六进制数据12*/13- (NSData *)escPrintBarCodeWithJustification:(int)justification14Type:(int)type15Width:(int)width16Height:(int)height17HRIPosition:(int)hri_position18Barcode:(NSString *)barcode19{20//以此为例,演示如何对 ESC-POS基础指令封装,形成功能21PTCommandESC *escCommand = [[PTCommandESC alloc] init]; //创建对象2223[escCommand initCMDQueue]; //初始化存放指令的数组2425/**26* 生成具体的指令,一般包括但不限定:对齐方式,打印起点,打印范围,二维码和图片宽度和高度等等。27* 每一条指令都会加入指令数组中去。28*/29[escCommand escSelectJustification:justification];30[escCommand escSelectPrintPositionOfHRICharacers:hri_position];31[escCommand escSetBarCodeWidth:width];32[escCommand escSetBarCodeHeight:height];33[escCommand escPrintBarCodeWithType:type Barcode:barcode];3435return [escCommand generateCMDData]; //从指令数组中取出命令,可以直接通过蓝牙或者 WiFi 发送出去,就可以打印一条二维码36}